package cn.bdqn.smbms.service;

import cn.bdqn.smbms.dao.BillDao;
import cn.bdqn.smbms.entity.Bill;
import cn.bdqn.smbms.util.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("billService")
public class BillServiceImpl implements BillService {
    @Autowired
    private BillDao billDao;

    @Override
    public PageBean<Bill> findByPage(String queryProductName, Integer queryProviderId, Integer isPayment, Integer pageNo, int pageSize) {
        PageBean<Bill> pageBean = new PageBean<>();
        pageBean.setPageSize(pageSize);
        pageBean.setTotalCount(billDao.getTotalCount(queryProductName,queryProviderId,isPayment));
        pageBean.setPageNo(pageNo);
        int from = (pageBean.getPageNo()-1)*pageSize;
        List<Bill> pageList = billDao.findByPage(queryProductName,queryProviderId,isPayment,from,pageSize);
        pageBean.setPageList(pageList);
        return pageBean;
    }

    @Override
    public int addBill(Bill bill) {
        return billDao.addBill(bill);
    }

    @Override
    public Bill findById(Integer id) {
        return billDao.findById(id);
    }

    @Override
    public int updateBill(Bill bill) {
        return billDao.updateBill(bill);
    }

    @Override
    public int delBill(Integer id) {
        return billDao.delBill(id);
    }

    @Override
    public boolean checkBillCode(String billCode) {
        Bill bill = billDao.findByBillCode(billCode);
        if(bill!=null){
            return true;
        }
        return false;
    }

}
